dnl Process this file with autoconf to produce a configure script

dnl ------------------------------------------------
dnl Initialization and Versioning
dnl ------------------------------------------------

AC_INIT([libvorbisidec], [1.2.1])
AC_CONFIG_SRCDIR([mdct.c])

AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE

dnl AM_MAINTAINER_MODE only provides the option to configure to enable it
AM_MAINTAINER_MODE

dnl Library versioning

V_LIB_CURRENT=1
V_LIB_REVISION=3
V_LIB_AGE=0
AC_SUBST(V_LIB_CURRENT)
AC_SUBST(V_LIB_REVISION)
AC_SUBST(V_LIB_AGE)

dnl --------------------------------------------------  
dnl Check for programs
dnl --------------------------------------------------  

dnl save $CFLAGS since AC_PROG_CC likes to insert "-g -O2"
dnl if $CFLAGS is blank
cflags_save="$CFLAGS"
AC_PROG_CC
AC_PROG_CPP
CFLAGS="$cflags_save"

LT_INIT

dnl --------------------------------------------------
dnl Set build flags based on environment
dnl --------------------------------------------------

dnl Set some target options

cflags_save="$CFLAGS"
ldflags_save="$LDFLAGS"
if test -z "$GCC"; then
        case $host in 
        arm-*-*)
                DEBUG="-g -D_ARM_ASSEM_" 
                CFLAGS="-O -D_ARM_ASSEM_"
                PROFILE="-p -g -O -D_ARM_ASSEM_" ;;
        *)
                DEBUG="-g"
                CFLAGS="-O"
                PROFILE="-g -p" ;;
        esac
else

        case $host in 
        arm-*-*)
                DEBUG="-g -Wall -W -D__NO_MATH_INLINES -fsigned-char -D_ARM_ASSEM_"
                CFLAGS="-O2 -Wall -W -D_ARM_ASSEM_ -fsigned-char"
                PROFILE="-Wall -W -pg -g -O2 -D_ARM_ASSEM_ -fsigned-char -fno-inline-functions";;

        *)
                DEBUG="-g -Wall -W -D__NO_MATH_INLINES -fsigned-char"
                CFLAGS="-O2 -Wall -W -fsigned-char"
                PROFILE="-Wall -W -pg -g -O2 -fsigned-char -fno-inline-functions";;
        esac
fi
CFLAGS="$CFLAGS $cflags_save -D_REENTRANT"
LDFLAGS="$LDFLAGS $ldflags_save"


# Test whenever ld supports -version-script
LT_PATH_LD
AC_PROG_LD_GNU
if test "x$lt_cv_prog_gnu_ld" = "xyes"; then
   SHLIB_VERSION_ARG="-Wl,--version-script=Version_script"
   LDFLAGS="$LDFLAGS $SHLIB_VERSION_ARG"
fi

dnl --------------------------------------------------
dnl Options 
dnl --------------------------------------------------

AC_ARG_ENABLE(
   low-accuracy,
   [  --enable-low-accuracy   enable 32 bit only multiply operations],
   CFLAGS="$CFLAGS -D_LOW_ACCURACY_"
)

dnl --------------------------------------------------
dnl Check for headers
dnl --------------------------------------------------

AC_CHECK_HEADER(memory.h,CFLAGS="$CFLAGS -DUSE_MEMORY_H",:)

dnl --------------------------------------------------
dnl Check for typedefs, structures, etc
dnl --------------------------------------------------

dnl none

dnl --------------------------------------------------
dnl Check for libraries
dnl --------------------------------------------------

PKG_PROG_PKG_CONFIG

HAVE_OGG=no
if test "x$PKG_CONFIG" != "x"
then
  PKG_CHECK_MODULES(OGG, ogg >= 1.0, HAVE_OGG=yes, HAVE_OGG=no)
fi
if test "x$HAVE_OGG" = "xno"
then
  dnl fall back to the old school test
  XIPH_PATH_OGG(, AC_MSG_ERROR(must have Ogg installed!))
  libs_save=$LIBS
  LIBS="$OGG_LIBS"
  AC_CHECK_FUNC(oggpack_writealign, , AC_MSG_ERROR(Ogg >= 1.0 required !))
  LIBS=$libs_save
fi

dnl --------------------------------------------------
dnl Check for library functions
dnl --------------------------------------------------

AC_FUNC_ALLOCA
AC_FUNC_MEMCMP

dnl --------------------------------------------------
dnl Do substitutions
dnl --------------------------------------------------

LIBS="$LIBS"

AC_SUBST(LIBS)
AC_SUBST(DEBUG)
AC_SUBST(PROFILE)

AC_CONFIG_FILES([Makefile Version_script vorbisidec.pc])
AC_OUTPUT
